package com.sfac.dao;

import com.sfac.account.Role;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * RoleDao
 */
@Mapper
@Repository
public interface RoleDao {

	@Insert("insert into account_role (role_name, create_date) values (#{roleName}, #{createDate})")
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	void insertRole(Role role);

	@Select("select * from account_role")
	List<Role> getRoles();

	@Select("select * from account_role r left join account_user_role ur on r.id = ur.role_id where ur.user_id = #{userId}")
	List<Role> getRolesByUserId(int userId);
}
